package com.booking.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;

import com.booking.bean.Users;
import com.booking.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
public class UserAction extends ActionSupport implements ModelDriven<Users>{
	
	@Autowired
	private Users user; 
	 
	@Autowired
    private UserService service;
	 
	@Override
	public Users getModel() {
		return user;
	} 
	
	//查询用户信息
	public String updateUser() throws Exception{ 
		
    	Users users = service.updateUser(user);
    	
    	if(users == null || users.equals("")){
			//修改失败
			ActionContext.getContext().put("regeditError", "修改失败，用户名已存在");			
		}else{
			//修改成功
			ActionContext.getContext().put("regeditError", "修改成功");			
		}
    	
		ActionContext.getContext().getSession().put("loginUser",users);
		return "frame";
	}
}
